<template>
	<model-page>
	<SearchVue :searchResult="serchText">
		<view  @click="cancelSearch">
			取消
		</view>
	</SearchVue>	
	<view class="tables">
		<view class="tables">
			<Table
			:headList="headList" 
			:tableData="tableData"
			:stateList="stateList"
			 :total="total"
			 v-model:pageNum="postData.pageNum"
			 :pageSize="postData.pageSize"
			  @checkPage="checkPage"
			></Table>
		</view>
	</view>
	</model-page>
</template>

<script setup>
import SearchVue from '../../../component/Search.vue';
import {notRecordList} from '@/api/dataInt.js'
import Table from '@/component/Table.vue'
import {nextTick, ref} from "vue"
import {onLoad} from '@dcloudio/uni-app'
	const stateList  = [
		{
			id:1,
			label:"详情",
			color:"#2778FF",
			path:"/packageDataInt/pages/dataIntDetail/dataIntDetail"
		}
	]
	const headList = ref([
		{
			title:"所属楼栋",
			props:"buildingName",
			width:"18%"
		},
		{
			title:"所属楼层",
			props:"floorName",
			width:"18%"
		},
		{
			title:"房间号",
			props:"roomNumber",
			width:"14%"
		},
		{
			title:"床号",
			props:"bedNumber",
			width:"18%"
		},
		{
			title:"老人名",
			props:"elderName",
			width:"12%"
		},
		{
			title:"操作",
			props:"nullState",
			width:"10%"
		},
	])
	const serchText = ref("")
	const cancelSearch = ()=>{
		 serchText.value = ""
		 delete postData.value.elderId
	     getTableList()
	}
	// 切换分页
	const checkPage = (type)=>{
		getTableList()
	}
	onLoad(()=>{
		uni.$on("undateElderId",(option)=>{
			const {type,searchResult} = option
			serchText.value = searchResult || ""
			postData.value.pageNum = 1
			postData.value.elderId = type
			getTableList()
		})

	})
	const tableData = ref([])
	const postData =ref({
		pageNum:1,
		pageSize:10,
	}) 
	const total = ref(0)
	const getTableList = async()=>{
		try{
		const {code,data:res} = await notRecordList(postData.value)
		if(code === 200){
			total.value = res.total
			tableData.value = res.list.map(val=>{
				return Object.assign(val,{nullState:"1"})
			})
		}
		}catch(e){
			//TODO handle the exception
		}
	}
	getTableList()
</script>

<style lang="less" scoped>
	.scan{
		width: 40rpx;
		height: 40rpx;
	}
	.tables{
		margin-top: 30rpx;
	}
</style>
